package com.naiterui.ehp.bs.emr.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.naiterui.ehp.bs.emr.entity.mongo.MedicalRecord;
import com.naiterui.ehp.bs.emr.entity.mongo.MedicalRecordDoctor;
import com.naiterui.ehp.bs.emr.service.IPatientIntelligentLabelService;
import com.naiterui.ehp.bs.emr.utils.PatientIntelligentLabelUtil;

/**
 * <pre>
 *      患者智能标签service实现
 * </pre>
 *
 * @author 王泽浩
 * @date 2018/7/30 下午2:51
 * @since 1.0.0
 */
@Service
public class PatientIntelligentLabelServiceImpl implements IPatientIntelligentLabelService {

    private static final Logger LOGGER = LoggerFactory.getLogger(PatientIntelligentLabelServiceImpl.class);

    @Override
    public void updateRevisitTimeAndDiagnosis(MedicalRecord medicalRecord) {
        Long doctorId = medicalRecord.getDoctorId();
        Long patientId = medicalRecord.getPatientId();
        MedicalRecordDoctor medicalRecordDoctor = medicalRecord.getRecordDoctor();
        if (medicalRecordDoctor.getRevisitFalg() == MedicalRecordDoctor.REVISITFALG_YES) {
            // 2018/7/30 下午1:46 王泽浩 将复诊时间放入到redis中
            PatientIntelligentLabelUtil.putRevisitTime(doctorId, patientId, medicalRecordDoctor.getRevisitDate());
        }
        List<String> diagnosisList = medicalRecordDoctor.getDiagnosisList();
        LOGGER.debug("获取病历诊断 {} ", diagnosisList);
        if (CollectionUtil.isNotEmpty(diagnosisList)) {
            PatientIntelligentLabelUtil.putDiagnosis(doctorId, patientId, diagnosisList);
        }
    }
}
